package main

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"net/http"
)

func heeloHeadler(c *gin.Context){
	c.JSON(http.StatusOK,gin.H{
		"message": "Hello www.topgoer.com!",
	})
}

//方法名大写 则是公共方法
func SetupRouter() *gin.Engine  {
	r:= gin.Default()
	r.GET("",heeloHeadler)
	return r
}

func loadBlog(e *gin.Engine){
	e.GET("/post",heeloHeadler)
}

func main() {
	r:=SetupRouter()
	if err := r.Run();err!=nil {
		fmt.Println("startup service failed, err:%v\n", err)
	}
}

type Option func(*gin.Engine)
//储存所有路由
var options =[]Option{}


// 加载多个APP的路由配置
func Include(opts ... Option)  {
	options =append(options,opts...)
}
//初始化
func Init()*gin.Engine  {
	r:= gin.New()
	//遍历路由
	for _,opt := range options{
		opt(r)
	}
	return r
}